package machineLearning.featurecalculator;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import rainbownlp.core.Artifact;
import rainbownlp.core.FeatureValuePair;
import rainbownlp.core.FeatureValuePair.FeatureName;
import rainbownlp.i2b2.sharedtask2012.ClinicalEvent;
import rainbownlp.i2b2.sharedtask2012.LinkExampleBuilder;
import rainbownlp.i2b2.sharedtask2012.TimexPhrase;
import rainbownlp.i2b2.sharedtask2012.featurecalculator.EventEvent.EventEventNormalizedDependencyFeatures;
import rainbownlp.machineLearning.IFeatureCalculator;
import rainbownlp.machineLearning.MLExample;
import rainbownlp.machineLearning.MLExampleFeature;
import rainbownlp.parser.DependencyLine;
import rainbownlp.util.StanfordDependencyUtil;
import rainbownlp.util.StringUtil;
import transientTables.TermsTFIDF;

public class DependencyFeatures implements IFeatureCalculator {
	public static void main(String[] args) throws Exception
	{
		List<MLExample> trainExamples = 
			MLExample.getAllExamples(true);;

		for(MLExample example_to_process: trainExamples)
		{
			DependencyFeatures sf =  new DependencyFeatures();
			
			
			sf.calculateFeatures(example_to_process);
			
		}		
		
	}
	@Override
	public void calculateFeatures(MLExample exampleToProcess) throws SQLException {
		Artifact sentence = exampleToProcess.getRelatedArtifact();
		
		ArrayList<DependencyLine> dep_lines = 
			StanfordDependencyUtil.parseDepLinesFromString(sentence.getStanDependency());
		for (DependencyLine dep: dep_lines)
		{
			String first_part = StringUtil.getTermByTermWordnet(dep.firstPart);
			String sec_part = StringUtil.getTermByTermWordnet(dep.secondPart);
			
			String lexicalized_dep = dep.relationName+"_"+first_part+"_"+sec_part;
			
			FeatureValuePair dep_feature = 
				FeatureValuePair.getInstance(FeatureName.Dependencies, lexicalized_dep,"1");
			MLExampleFeature.setFeatureExample(exampleToProcess, dep_feature);
			
		}
		
	}

}
